package org.xiji.single;

/**
 * 单例模式
 */
public class SingleMain {
    public static void main(String[] args) {

        /**
         * 创建普通对象
         */
        Singer singer = new Singer();
        Singer singer1 = new Singer();
        System.out.println("普通对象是否相等" +singer.equals(singer1));
        //肯定是不相等的
        System.out.println("==================================================");
        /**
         * 通过饿汉式单例模式创建
         */
        SingleEager singleEager = SingleEager.getSingleEager();
        SingleEager singleEager1 = SingleEager.getSingleEager();

        System.out.println("单例模式对象是否相等" +singleEager.equals(singleEager1));
        //肯定是相等的
        System.out.println("==================================================");

        /**
         *  通过懒汉式线程安全的单例模式创建  + synchronized锁
         */
        SingleLazySafe singleLazySafe = SingleLazySafe.getInstance();

        /**
         * 通过懒汉式线程不安全的单例模式创建  不加 synchronized锁
         */
        SingleLazyUnSafe singleLazyUnSafe = SingleLazyUnSafe.getInstance();
    }
}
